﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace DBService
{
	public partial class DlgAddDepartment : System.Windows.Forms.Form
	{
		public DlgAddDepartment(DlgServerManager main)
		{
			this.InitializeComponent();
			this.mainForm = main;
			this.parent = this.mainForm.CurrentDepartment;
		}

		private void DlgAddDepartment_Load(object sender, EventArgs e)
		{
			this.txtParent.Text = this.mainForm.CurrentDepartment.Name;
		}

		private void btnAdd_Click(object sender, EventArgs e)
		{
			try
			{
				DbDepartment department = new DbDepartment(this.txtName.Text, this.rtxDesc.Text, this.parent.Id);
				this.parent.AddSubDepartment(department);
			}
			catch
			{
				MessageBox.Show("添加失败，请检查是否有重名。");
			}
		}

		private DlgServerManager mainForm;

		private DbDepartment parent;
	}
}
